package com.blvtphan.tipocketclubs.adapter;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.blvtphan.tipocketclubs.R;
import com.blvtphan.tipocketclubs.custom.CustomTextView;
import com.blvtphan.tipocketclubs.model.RewardsModel;
import com.blvtphan.tipocketclubs.util.DateTimeUtils;

public class RewardTrackerAdapter extends BaseAdapter{

	private List<RewardsModel> lstRewards;
	private Context mContext;
	
	public RewardTrackerAdapter(Context context, List<RewardsModel> lstRewards) {
		this.mContext = context;
		this.lstRewards = lstRewards;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return lstRewards.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return lstRewards.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		View rowView = inflater.inflate(R.layout.item_rewards_transaction, parent, false);
		
		CustomTextView title = (CustomTextView)rowView.findViewById(R.id.txt_reward_tracker_title);
		CustomTextView period = (CustomTextView)rowView.findViewById(R.id.txt_reward_tracker_period);
		
		String fromDate = DateTimeUtils.convertFormatDateToString(mContext, lstRewards.get(position).getFromDate().substring(0, 9));
		fromDate += lstRewards.get(position).getFromDate().substring(10);
		Log.i("DateTime", fromDate);
		String toDate = DateTimeUtils.convertFormatDateToString(mContext, lstRewards.get(position).getToDate().substring(0, 9));
		toDate += lstRewards.get(position).getToDate().substring(10);
		Log.i("DateTime", toDate);
		
		String periodString = mContext.getResources().getString(R.string.text_from) + " "
				+ fromDate + " "
				+ mContext.getResources().getString(R.string.text_to) + " "
				+ toDate;
		
		title.setText(lstRewards.get(position).getTitle());
		period.setText(periodString);
		
		return rowView;
	}

}
